package zh.keep.all

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import zh.keep.all.account.AccountUtils
import zh.keep.all.services.ForegroundService
import zh.keep.all.wallpaper.WallpaperUtil
import java.text.SimpleDateFormat
import java.util.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        CoroutineScope(Dispatchers.IO).launch {
            while (true) {
                delay(1000)
                Log.d(
                    "正在运行",
                    "run: " + SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date(System.currentTimeMillis()))
                )
            }
        }
        if (!queryBatteryOptimizeStatus()) {
            Log.e("电池优化", "未忽略电池优化: ")
            requestIgnoreBatteryOptimizations()
        } else {
            Log.d("电池优化", "已忽略电池优化: ")
        }
        // 账户同步拉活
        AccountUtils.addAccount(this)
        // 开始同步
        AccountUtils.autoSyncStart()
        //开启通知监听权限
        notificationMonitor()
    }

    fun setWall(view: View) {
        WallpaperUtil.setLiveWallpaper(this, this, 2)
    }

}